<template>
  <div class="top">
    <div class="content">
      <div class="left" @click="goHome">
        <img src="../../assets/images/logo.png" alt="" class="img" />
        <p class="name">医院预约挂号统一平台</p>
      </div>
      <div class="right">
        <p class="help">帮助中心</p>
        <p class="login" @click="Login" v-if="!UserStore.UserName">登录/注册</p>
        <el-dropdown v-else class="login">
          <span class="el-dropdown-link">
           {{ UserStore.UserName }}
            <el-icon class="el-icon--right">
              <arrow-down />
            </el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="goUser('/user/authentication')">实名认证</el-dropdown-item>
              <el-dropdown-item @click="goUser('/user/orders')">挂号订单</el-dropdown-item>
              <el-dropdown-item @click="goUser('/user/manage')">就诊人管理</el-dropdown-item>
            <el-dropdown-item @click="LoginOut">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
//引入路由器对象
import { useRouter } from "vue-router";
//引入用户仓库
import useUserStore from "@/store/modules/User";
//引入图标组件
import { ArrowDown } from '@element-plus/icons-vue'
import { ElMessage } from "element-plus";
//获取仓库
let UserStore = useUserStore();
//创建路由器对象
let $router = useRouter();
//点击返回首页
const goHome = () => {
  $router.push("/");
};
//登录按钮回调
const Login = () => {
  //显示对话框
  UserStore.dialogFormVisible = true;
};
//用户退出登录的回调
const LoginOut = ()=>{
  UserStore.LogoOut();
 //跳转到首页
 $router.push({
  path:'/'
 })
 //提示
 ElMessage({
  type:'success',
  message:'退出成功'
 })
}
//下拉菜单路由跳转的回调
const goUser = (path: string) => {
  $router.push({
    path,
  })
}
</script>

<style scoped lang="scss">
.top {
  position: fixed;
  top: 0;
  z-index: 999;
  width: 100%;
  height: 70px;
  background-color: #fff;
  display: flex;
  justify-content: center;
  .content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 1300px;
    height: 70px;

    .left {
      display: flex;
      align-items: center;
      .img {
        width: 60px;
        height: 60px;
        margin-right: 10px;
      }
      .name {
        font-size: 30px;
        font-weight: 700;
        opacity: 0.8;
        color: #55a6fe;
      }
    }
    .right {
      display: flex;
      font-size: 15px;
      color: #848282;
      .login {
        margin-left: 10px;
      }
    }
  }
}
</style>
